#define _CRT_SECURE_NO_WARNINGS 1
int* intersection(int* nums1, int nums1Size, int* nums2, int nums2Size, int* returnSize) {
    int* ret_nums = (int*)malloc(sizeof(int) * (nums1Size + nums2Size));
    int count1[1000] = { 0 };
    int count2[1000] = { 0 };
    *returnSize = 0;
    int i = 0;
    int j = 0;
    int max1 = nums1[0];
    for (i = 0;i < nums1Size;i++)
    {
        if (nums1[i] > max1)
        {
            max1 = nums1[i];
        }
    }
    int range1 = max1 + 1;
    for (i = 0;i < nums1Size;i++)
    {
        count1[nums1[i]]++;
    }
    int max2 = nums2[0];
    for (i = 0;i < nums2Size;i++)
    {
        if (nums2[i] > max2)
        {
            max2 = nums2[i];
        }
    }
    int range2 = max2 + 1;
    for (i = 0;i < nums2Size;i++)
    {
        count2[nums2[i]]++;
    }
    int min_range = range1 > range2 ? range2 : range1;
    for (i = 0; i < min_range;i++)
    {
        if (count1[i] != 0 && count2[i] != 0)
        {
            ret_nums[j++] = i;
            (*returnSize)++;
        }
    }
    return ret_nums;
}